#include "pch.hpp"
#include "D3D11EffectTechnique.hpp"
#include "D3D11Mesh.hpp"

using namespace Engine;
using namespace Engine::Video;




D3D11EffectTechnique::D3D11EffectTechnique(const ID3D11DevicePtr& device)
	: m_device(device)
{}
///////////////////////////////////////////////////////////////////////////////////////////////////




EffectPass& D3D11EffectTechnique::addPass(const std::string& name)
{
	if(m_passes.find(name) != m_passes.end())
		BOOSTEXT_THROW(exception(format("There already is a pass named '%1%'") % name));

	return m_passes.insert(std::make_pair(name, D3D11EffectPass(m_device))).first->second;
}
///////////////////////////////////////////////////////////////////////////////////////////////////




void D3D11EffectTechnique::draw(const ID3D11DevicePtr& device, D3D11DeviceContext& context, const RenderNode::ptr& node)
{
	foreach(const RenderPass& pass, node->passes)
	{
		Passes::iterator i = m_passes.find(pass.name);
		if(i == m_passes.end())
			BOOSTEXT_THROW(exception(format("There is no pass named '%1%'") % pass.name));

		i->second.draw(device, context, pass);
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////

void D3D11EffectTechnique::optimize()
{
	foreach(Pass& pass, m_passes)
	{
		pass.second.optimize();
	}
}
///////////////////////////////////////////////////////////////////////////////////////////////////
